package ext.tianma.part.processors;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import wt.part.WTPart;
import wt.util.WTException;

import com.ptc.core.components.forms.DefaultObjectFormProcessor;
import com.ptc.core.components.forms.FormProcessingStatus;
import com.ptc.core.components.forms.FormResult;
import com.ptc.core.components.util.FeedbackMessage;
import com.ptc.core.ui.resources.FeedbackType;
import com.ptc.netmarkets.model.NmOid;
import com.ptc.netmarkets.util.beans.NmCommandBean;

import ext.com.core.CoreUtil;
import ext.com.iba.IBAUtil;
import ext.com.workflow.WorkflowUtil;

public class UpdateMaterialDetailsProcessors extends DefaultObjectFormProcessor{

	@Override
	public FormResult doOperation(NmCommandBean nmcommandBean, List list)throws WTException {
		FormResult formResult = new FormResult(FormProcessingStatus.SUCCESS);
		
		NmOid nmoid = nmcommandBean.getActionOid();
		
		if( nmoid != null ){
			Object object = nmoid.getRefObject();
			
			if( object != null && object instanceof WTPart ){
				WTPart part = ( WTPart )object;
				
				if( part != null ){
					HttpServletRequest request = nmcommandBean.getRequest();
					
					String[] parameterValues = request.getParameterValues( "materialDetails" );

					if( parameterValues != null ){
						
						String materialDetails = parameterValues[0];
						
						if( materialDetails != null && !materialDetails.trim().isEmpty() ){
							
							if( !WorkflowUtil.isObjectCheckedOut( part ) ){
								part = (WTPart)CoreUtil.checkoutObject( part );
							}
							
							IBAUtil.forceSetIBAValue(part, "materialDetails", materialDetails);
							
							CoreUtil.checkinObject( part , "物料详细描述修改" );
							formResult.addFeedbackMessage( new  FeedbackMessage(
									FeedbackType.SUCCESS, null, "物料详细描述修改成功", null, new String[] {} ) );
						}
					}
				}
			}
		}
		return formResult;
	}

}
